import com.alibaba.fastjson.JSON;
import com.size.mall.util.HttpclientUtil;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class AuthorTest2 {

    //
    @Test
    public void getAuthorizationCode() {

        // api key 3660936033
        //  回调地址 http://passport.sizemall.com/success


        String rs = HttpclientUtil.doGet("https://api.weibo.com/oauth2/authorize?client_id=3660936033&response_type" +
                                                 "=code" +
                                                 "&redirect_uri=http://passport.sizemall.com:9040/vlogin");

        System.out.println(rs);

        // String s1 = HttpclientUtil.doGet("https://api.weibo.com/oauth2/authorize?client_id=187638711&response_type" +
        //                                          "=code&redirect_uri=http://passport.gmall.com:8085/vlogin");
        //
        // System.out.println(s1);

    }


    @Test
    public void getAccess_token() {
        // 换取access_token
        // client_secret=a79777bba04ac70d973ee002d27ed58c
        // client_id=187638711
        String s3 = "https://api.weibo.com/oauth2/access_token?";//?client_id=187638711&client_secret
        // =a79777bba04ac70d973ee002d27ed58c&grant_type=authorization_code&redirect_uri=http://passport.gmall
        // .com:8085/vlogin&code=CODE";
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("client_id", "3660936033");
        paramMap.put("client_secret", "a41794c7bcde974dea18f9382c2ebf91");
        paramMap.put("grant_type", "authorization_code");
        paramMap.put("redirect_uri", "http://passport.sizemall.com:9040/vlogin");
        paramMap.put("code", "93084aa4b338a666df8f7c35874edc67");//
        // 授权有效期内可以使用，没新生成一次授权码，说明用户对第三方数据进行重启授权，之前的access_token和授权码全部过期
        String access_token_json = HttpclientUtil.doPost(s3, paramMap);

        Map<String, String> access_map = JSON.parseObject(access_token_json, Map.class);

        System.out.println(access_map.get("access_token"));
        System.out.println(access_map.get("uid"));

        // return access_map.get("access_token");
    }


    @Test
    public void getUser_info() {

        // 4 用access_token查询用户信息
        String access_token = "2.008F1GuC4hukzD55066977d0yOSD8C";
        String uid = "2661247665";
        String s4 = "https://api.weibo.com/2/users/show.json?access_token=" + access_token + "&uid=" + uid;
        String user_json = HttpclientUtil.doGet(s4);
        Map<String, String> user_map = JSON.parseObject(user_json, Map.class);

        // System.out.println(user_map.get("1"));


        // return user_map;
    }


}
